package com.framework.model.login;

import com.framework.model.system.vo.SystemUserVo;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.io.Serializable;
import java.util.Collection;

/**
 * @author 龘鵺
 * @className com.framework.common.model.login
 * @description 自定义用户类
 * @datetime 2022-01-09 11:11:11
 * @version 1.0
 */
public class CustomUser extends User implements Serializable {
    private static final long serialVersionUID = -1L;
    private SystemUserVo systemUserVo;

    public CustomUser(SystemUserVo systemUserVo, Collection<? extends GrantedAuthority> authorities) {
        super(systemUserVo.getAccount(), "", authorities);
        this.systemUserVo = systemUserVo;
    }

    public SystemUserVo getSystemUserVo() {
        return systemUserVo;
    }

    public void setSystemUser(SystemUserVo systemUserVo) {
        this.systemUserVo = systemUserVo;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        CustomUser that = (CustomUser) o;

        return systemUserVo != null ? systemUserVo.equals(that.systemUserVo) : that.systemUserVo == null;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + (systemUserVo != null ? systemUserVo.hashCode() : 0);
        return result;
    }
}